var express = require('express');
var router = express.Router();
var {courseModel, chapterModel} = require('../model/model.js')

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with a resource');
});

router.get('/courselist',async(req,res)=>{
  const publisher = req.query.publisher
  let data = await courseModel.find({publisher : publisher})
  res.send({
    code :200,
    data
  })
})

router.delete('/delcourse',async(req,res)=>{
  const {id,arr} = req.query
  console.log(arr,'接受的数组');
  await courseModel.deleteOne({_id : id})
  await chapterModel.deleteMany({_id : {$in : arr}})

  res.send({
    code : 200,
    message : '删除成功'
  })
})


module.exports = router;
